The usage of memalign():
- fit within cache lines to reduce the number of cache misses.
- vectorization operators require a block of memory aligned to a multiple of 2.
We call failing to free memory leak.
mmap():
- lazy. It does not immediately allocate physical memory for the requested allocation but populates the page table with entries pointing to a special zero page and marks the page as read only.
- you can mmap() a terabyte of virtual memory on a machine with only a gigabyte of DRAM.
The difference of mmap() and malloc();
- mmap() is to obtain memory (virtual address space) from the kernel.
- malloc() is to satisfy user requests for heap storage by reusing freed memory whenever possible.